package gui.panel;

import gui.MainWindow;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import listeners.ConnectButtonListener;
import listeners.ExitListener;


public class ConnectionPanel extends JPanel {

	private JTextField txtUsername;
	private JButton btnConnect;
	private JButton btnExit;
	
	public ConnectionPanel() {
		super(new GridLayout(3, 1, 10, 10));
		
		this.initComponents();
		this.addComponents();
		this.addListeners();
	}

	private void addListeners() {
		// TODO Auto-generated method stub
		this.btnConnect.addActionListener(new ConnectButtonListener(this));
		this.btnExit.addActionListener(new ExitListener());
	}

	private void initComponents() {
		// TODO Auto-generated method stub
		this.txtUsername = new JTextField(20);
		this.btnConnect = new JButton("Connect");
		this.btnExit = new JButton("Exit");
	}

	private void addComponents() {
		// TODO Auto-generated method stub
		JPanel panTitle = new JPanel(new BorderLayout());
		JPanel panUsername = new JPanel(new FlowLayout());
		JPanel panButtons = new JPanel(new FlowLayout());

		panTitle.add(new JLabel("Welcome to our P2P Chat System"));
		
		panUsername.add(new JLabel("Please enter your username"));
		panUsername.add(this.txtUsername);
		
		panButtons.add(this.btnConnect);
		panButtons.add(this.btnExit);
		
		this.add(panTitle, BorderLayout.CENTER);
		this.add(panUsername);
		this.add(panButtons);
		
	}

	public JTextField getTxtUsername() {
		return txtUsername;
	}

	public void setTxtUsername(JTextField txtUsername) {
		this.txtUsername = txtUsername;
	}

	public JButton getBtnConnect() {
		return btnConnect;
	}

	public void setBtnConnect(JButton btnConnect) {
		this.btnConnect = btnConnect;
	}

	public JButton getBtnExit() {
		return btnExit;
	}

	public void setBtnExit(JButton btnExit) {
		this.btnExit = btnExit;
	}
}
